package com.czk.springcloud.comtroller;

import com.czk.springcloud.entity.CommonResult;
import com.czk.springcloud.entity.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author:ChenZhangKun
 * @Date: 2020/12/26 20:16
 */
@RestController
@RequestMapping("/payment")
public class PaymentController {
    @Value("${server.port}")
    private String serverPort;
    public static Map<Long, Payment> map = new HashMap<>(10);

    static {
        map.put(1L, new Payment(1L, "4fde4f4f5df54d5f"));
        map.put(2L, new Payment(2L, "4fde4f4f5df54d5f"));
        map.put(3L, new Payment(3L, "4fde4f4f5df54d5f"));

    }

    @GetMapping("/sql/{id}")
    public CommonResult<Payment> paymentSql(@PathVariable("id") Long id) {
        Payment payment = map.get(id);
        CommonResult<Payment> result = new CommonResult<>(200, "from sql" + serverPort, payment);
        return result;
    }
}
